package ustc.xiaoyang.controller;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import ustc.xiaoyang.pojo.Result;
import ustc.xiaoyang.pojo.Student;
import ustc.xiaoyang.pojo.dto.StudentPageQueryDTO;
import ustc.xiaoyang.service.StudentService;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/students")
public class StudentController {
    private StudentService studentService;
    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }

    @GetMapping
    public Result pageList(StudentPageQueryDTO studentPageQueryDTO){
        log.info("分页查询,查询参数：{}", studentPageQueryDTO);
        return Result.success(studentService.pageList(studentPageQueryDTO));

    }

    @PostMapping
    public Result add(@RequestBody Student student){
        log.info("添加学生,学生信息：{}", student);
        studentService.add(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("查询学生信息,id：{}", id);
        return Result.success(studentService.getById(id));
    }

    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改学生信息：{}", student);
        studentService.update(student);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        log.info("删除学生信息,id：{}", ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }

    @PutMapping("/violation/{id}/{score}")
    public Result updateViolation(@PathVariable Integer id, @PathVariable Integer score){
        log.info("学生违规扣分,id：{},score:{}", id,score);
        studentService.updateViolation(id, score);
        return Result.success();
    }


}
